package b4.scene.town
{
	import b4.model.town.TownModel;
	import b4.scene.basic.*;
	import b4.widget.main.MainFuncBar;
	import b4.widget.system.SystemFuncBar;
	import b4.widget.user.ExpBar;
	import b4.widget.user.UserPane;
	
	import com.greensock.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.text.*;

	public class TownScene extends BasicScene
	{
		static private var instance:TownScene;
		//城镇
		private var townLayer:Sprite;
		//用户面板
		public var userPane:UserPane;
		//系统面板
		public var systemFuncBar:SystemFuncBar;
		//主功能条
		public var mainFuncBar:MainFuncBar;
		//经验条
		public var expBar:ExpBar;
		
		public function TownScene()
		{
			super();
			//城市层
			townLayer = new Sprite();
			addChild(townLayer);
			//控件层
			var widgetLayer:Sprite = new Sprite();
			addChild(widgetLayer);
			//用户面板
			userPane = new UserPane();
			widgetLayer.addChild(userPane);
			//系统面板
			systemFuncBar = new SystemFuncBar();
			widgetLayer.addChild(systemFuncBar);
			//主功能条
			mainFuncBar = new MainFuncBar();
			widgetLayer.addChild(mainFuncBar);
			//经验条
			expBar = new ExpBar();
			widgetLayer.addChild(expBar);
		}
		
		static public function getInstance():TownScene
		{
			if (!instance)
				instance = new TownScene();
			return instance;
		}
		
		private function clearTownLayer():void
		{
			if (townLayer.numChildren > 0)
			{
				var town:Town = townLayer.getChildAt(0) as Town;
				townLayer.removeChildAt(0);
				town.destroy();
			}
		}
		
		public function loadTown(townModel:TownModel):void
		{
			//载入用户城镇
			clearTownLayer();
			var town:Town = new Town(townModel);
			townModel.getTownInfo();
			townLayer.addChild(town);
		}
	}
}